package com.yuetong.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.business.domain.YtAssignedTask;
import com.yuetong.business.service.IYtAssignedTaskService;
import com.yuetong.common.utils.poi.ExcelUtil;
import com.yuetong.common.core.page.TableDataInfo;

/**
 * 指派维修任务，用于记录维修任务的指派和完成情况Controller
 * 
 * @author  卓晓君
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/business/task")
public class YtAssignedTaskController extends BaseController
{
    @Autowired
    private IYtAssignedTaskService ytAssignedTaskService;

    /**
     * 查询指派维修任务，用于记录维修任务的指派和完成情况列表
     */
    @PreAuthorize("@ss.hasPermi('business:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(YtAssignedTask ytAssignedTask)
    {
        startPage();
        List<YtAssignedTask> list = ytAssignedTaskService.selectYtAssignedTaskList(ytAssignedTask);
        return getDataTable(list);
    }

    /**
     * 导出指派维修任务，用于记录维修任务的指派和完成情况列表
     */
    @PreAuthorize("@ss.hasPermi('business:task:export')")
    @Log(title = "指派维修任务，用于记录维修任务的指派和完成情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtAssignedTask ytAssignedTask)
    {
        List<YtAssignedTask> list = ytAssignedTaskService.selectYtAssignedTaskList(ytAssignedTask);
        ExcelUtil<YtAssignedTask> util = new ExcelUtil<YtAssignedTask>(YtAssignedTask.class);
        util.exportExcel(response, list, "指派维修任务，用于记录维修任务的指派和完成情况数据");
    }

    /**
     * 获取指派维修任务，用于记录维修任务的指派和完成情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(ytAssignedTaskService.selectYtAssignedTaskByTaskId(taskId));
    }

    /**
     * 新增指派维修任务，用于记录维修任务的指派和完成情况
     */
    @PreAuthorize("@ss.hasPermi('business:task:add')")
    @Log(title = "指派维修任务，用于记录维修任务的指派和完成情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtAssignedTask ytAssignedTask)
    {
        return toAjax(ytAssignedTaskService.insertYtAssignedTask(ytAssignedTask));
    }

    /**
     * 修改指派维修任务，用于记录维修任务的指派和完成情况
     */
    @PreAuthorize("@ss.hasPermi('business:task:edit')")
    @Log(title = "指派维修任务，用于记录维修任务的指派和完成情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtAssignedTask ytAssignedTask)
    {
        return toAjax(ytAssignedTaskService.updateYtAssignedTask(ytAssignedTask));
    }

    /**
     * 删除指派维修任务，用于记录维修任务的指派和完成情况
     */
    @PreAuthorize("@ss.hasPermi('business:task:remove')")
    @Log(title = "指派维修任务，用于记录维修任务的指派和完成情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(ytAssignedTaskService.deleteYtAssignedTaskByTaskIds(taskIds));
    }
}
